home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / util / shell / axuucp_0_1.lha / axsh / rexx / ax-uuxqt.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1995-03-22  |  5.0 KB  |  192 lines

  1. /****** axuucp/ax-uuxqt ******************************************************
  2. *
  3. *   NAME
  4. *    ax-uuxqt - Import UUCP mail and news executing UUCP command files
  5. *
  6. *   SYNOPSIS
  7. *    rx ax-uuxqt.rexx [feed]
  8. *
  9. *   DESCRIPTION
  10. *
  11. *   BUGS
  12. *    Due to some bugs (features ?) in /bin/mailserver 1.15 (which does not
  13. *    fully support RFC 822 Mail headers,  mails to and from unroutable
  14. *    systems will get lost!
  15. *
  16. *   AUTHOR
  17. *    Tobias Ferber <tf@ganymed.hall.sub.org>
  18. *
  19. ******************************************************************************
  20. *
  21. */
  22.  
  23. feed = left(arg(1),min(length(arg(1)),7))
  24.  
  25. if words(feed) < 1 then do
  26.   say 'usage: ax-uucico [feed]'
  27.   exit 10
  28.   end
  29.  
  30. spooldir = strfmt(axconfig("axuucp.spooldir"),"%u",feed)
  31.  
  32. if ~exists(spooldir) then do
  33.   say 'ax-uuxqt: No such spool directory "'spooldir'"'
  34.   exit 10
  35.   end
  36.  
  37. axmail   = axconfig("mail")
  38. aka      = axconfig("thismachine")
  39. tempfile = "T:ax-uuxqt." || pragma('Id')
  40. pat      = "X." || feed || "?" || "????"
  41.  
  42. files=0; news=0; mails=0; errors=0;
  43.  
  44. address command 'List FILES DIR "'spooldir'" PAT "'pat'" LFORMAT "%p%n" > "'tempfile'"'
  45.  
  46. call open('fp',tempfile)
  47. do until eof('fp')
  48.   xfile= readln('fp')
  49.   if words(xfile) > 0 then do
  50.     err= uuxqt(xfile)
  51.     if err>0 then errors= errors+1
  52.     files= files+1;
  53.     end
  54.   end
  55.  
  56. call close('fp')
  57. address command 'Delete QUIET "'tempfile'"'
  58. say 'ax-uuxqt:' files 'files,' news 'news,' mails 'mails,' errors 'errors'
  59. exit
  60.  
  61.  
  62. uuxqt: procedure expose spooldir aka axmail news mails;
  63.   parse arg xfile
  64.   dfile=''; cmd=''; err= 0
  65.   call open('xfp',xfile)
  66.   do until eof('xfp')
  67.     str= readln('xfp')
  68.     if words(str) > 0 then do
  69.       parse var str lhs ' ' rhs
  70.       select
  71.         when (upper(lhs)='F') | (upper(lhs)='I') then dfile= rhs
  72.         when (upper(lhs)='C') then cmd=rhs
  73.         otherwise nop
  74.         end
  75.       end
  76.     end
  77.   call close('xfp')
  78.  
  79.   if (words(dfile) > 0) & (words(cmd) > 0) then do
  80.     dfile= spooldir || dfile
  81.     if exists(dfile) then do
  82.       select
  83.         when upper(left(cmd,5)) = "RNEWS" then do
  84.           /*say xfile': posting news from "'dfile'"'*/
  85.           address command 'rx axsh:rexx/ax-rnews.rexx < "'dfile'"'
  86.           news= news+1
  87.           end
  88.         when upper(left(cmd,5)) = "RMAIL" then do
  89.           address command 'rx axsh:rexx/ax-rmail.rexx < "'dfile'"'
  90. /*
  91.           toaddr= substr(cmd,7); user=''; domain=''
  92.           select
  93.             when pos('@',toaddr) > 0 then parse var toaddr user '@' domain
  94.             when pos('!',toaddr) > 0 then parse var toaddr domain '!' user
  95.             otherwise user= toaddr
  96.             end
  97.           if (words(domain) = 0) | (domain = aka) then do
  98.             say xfile': sending mail to "'user'"'
  99.             mbox= axmail || user
  100.             /*address command 'AXsh:bin/mailserver "'dfile'"'*/
  101.             address command 'Type "'dfile'" >> "'axmail || user'"'
  102.             address command 'Echo "" >> "'mbox'"' /* force 'body null' */
  103. */
  104.             mails= mails+1
  105. /*
  106.             end
  107.           else do
  108.             say xfile': cannot deliver mail to "'toaddr'" (no route to "'domain'")'
  109.             err= 1
  110.             end
  111. */
  112.           end
  113.         otherwise do
  114.           say xfile': operation not permitted "'cmd'"'
  115.           err= 2
  116.           end
  117.         end /* select */
  118.       if ((err=0) & exists(dfile)) then address command 'Delete QUIET "'dfile'"'
  119.       end
  120.     else do
  121.       say xfile': file "'dfile'" not found'
  122.       err= 3
  123.       end
  124.     if err=0 then address command 'Delete QUIET "'xfile'"'
  125.     end
  126.   else do
  127.     say xfile': missing command (C) or filename (F,I)'
  128.     err= 4
  129.     end
  130.  
  131.   return err
  132.  
  133.  
  134. /*@<axconfig><strfmt>*/
  135.  
  136. /* get an AXsh configuration value */
  137.  
  138. axconfig: procedure
  139.   tempfile = "T:axconfig." || pragma('Id')
  140.   rc_index  = "AXsh:rexx/rc.index"
  141.   var_val=""; var_file=""; var_defval="";
  142.  
  143.   parse upper arg var_name
  144.   if left(var_name,1) ~= '%' then var_name = '%'var_name
  145.   if right(var_name,1) ~= ':' then var_name = var_name':'
  146.  
  147.   if open('idx',rc_index,'Read') then do
  148.     do until (eof('idx') | (var_file~=''))
  149.       str= translate(readln('idx'),' ',d2c(9))
  150.       if words(str) > 0 then do
  151.         parse var str vname ' ' fname '"' defval '"'
  152.         if upper(vname) = var_name then do
  153.           var_file= strip(fname,'B',' 'd2c(9))
  154.           var_defval= defval
  155.           end
  156.         end
  157.       end
  158.     call close('idx')
  159.     end
  160.   else say 'Could not read "'rc_index'"'
  161.  
  162.   if words(var_file) > 0 then do
  163.     if open('rc',var_file,'Read') then do
  164.       do until (eof('rc') | (var_val~=''))
  165.         str= translate(readln('rc'),' ',d2c(9))
  166.         if upper(word(str,1)) = var_name then var_val = strip(readln('rc'),'B',' 'd2c(9))
  167.         end
  168.       call close('rc')
  169.       end
  170.     else say 'Could not examine "'var_file'" for' var_name
  171.     end
  172.   else do
  173.     if words(var_defval) > 0 then var_val= var_defval
  174.     else say 'No such config variable:' var_name
  175.     end
  176.  
  177.   return var_val
  178.  
  179.  
  180. /* substitute all occurences of 'fmt' in 'str' by 'val' */
  181.  
  182. strfmt: procedure
  183.   parse arg str,fmt,val
  184.   p= pos(fmt,str)
  185.   do while p>0
  186.     str= left(str,p-1) || val || substr(str,p+length(fmt))
  187.     p= pos(fmt,str)
  188.     end
  189.   return str
  190.  
  191.  
  192.